<template>
  <div class="confitm">
    <div class="tob">
      <div class="imgs" @click="toshang">
        <img src="../assets/syb.png" alt="" />
      </div>
      <div class="text">地址选项</div>
     
    </div>
    <div class="addr">
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        disabled-text="以下地址超出配送范围"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="ontoDIzi"
      />
    </div>
    
  </div>
</template>

<script>
// 地址
import { Toast } from "vant";
import { ContactCard } from "vant";
import API from "../http/API";
import { AddressList } from "vant";

export default {
  name: "confirm",
  components: {
    [ContactCard.name]: ContactCard,
    [Toast.name]: Toast,
    [AddressList.name]: AddressList,
  },
  data() {
    return {
      chosenAddressId: "1",
      list: [],
      disabledList: [
        {
          id: "3",
          name: "王五",
          tel: "1320000000",
          address: "浙江省杭州市滨江区江南大道 15 号",
        },
      ],
    };
  },
  created() {
    this.http();
    this.isRouter();
  },
  methods: {
    isRouter() {
      // this.$router;
    },
    onEdit(item, index) {
      console.log("编辑");
      console.log(item);
      this.$router.push({ name: "selection", params: { datas:(item) } });
    },
    onAdd() {
      this.$router.push("/selection");
    },
    // 当用户什么都不想做就只是想返回上一层时候
    toshang() {
      this.$router.go(-1);
    },
    // 选中地址的时候返回去上一层
    ontoDIzi(item, index) {
      this.$store.commit("address", item);
      console.log(this.$store.state.address);
      this.$router.go(-1);
    },
    http() {
      this.$get(
        API.GET_ADDRESS_SAVE,
        {
          params: {
            token: localStorage.getItem("token"),
          },
        }
        // 请求方式：post
        // 参数：
        // ①封装 token
        // ②name：收货人姓名
        // ③tel：电话
        // ④province：省
        // ⑤city：市
        // ⑥county：区
        // ⑦addressDetail：详细地址
        // ⑧isDefault：是否默认
      ).then((res) => {
        if (res.errmsg == "成功") {
          // Toast({
          //   message: "保存成功",
          //   position: "top",
          // });
          // 进行数据的处理
          this.datamos(res);
        }
        // console.log(res);
      });
    },

    datamos(e) {
      console.log(e);
      for (let index = 0; index < e.data.list.length; index++) {
        this.list.push({
          id: e.data.list[index].id,
          name: e.data.list[index].name,
          tel: e.data.list[index].tel,
          address:
            e.data.list[index].province +
            e.data.list[index].city +
            e.data.list[index].county +
            e.data.list[index].addressDetail,
          isDefault: e.data.list[index].isDefault,
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.confitm {
  width: 100%;
  height: 100%;
  background-color: @background;
  .tob {
    height: 50px;
    display: flex;
    align-items: center;
    .sj();
    .text {
      margin-left: 5px;
      margin-top: 3px;
      font-size: 17px;
    }
   
}
  }
  .imgs {
    width: 20px;
    height: 20px;
    // border: 1px solid #000;
    img {
      width: 100%;
      height: 100%;
    }
  
  
}
.qding {
  height: 40px;
  margin-left: 10px;
  margin-right: 10px;
  border-radius: 40px;
  background-color: rgb(235, 122, 114);
  font-size: 17px;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>